<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="com.vb.webpress.data.*" %>
<%
	boolean login = false;
	boolean release = false;
	session = request.getSession(false);	
	
	if(session != null){
		
		if(session.getAttribute("account") != null)
			login = true;
		else
			session.invalidate();
		
		if(request.getParameter("action") != null
				&& request.getParameter("action").equals("logout")){
			session.invalidate();
			login = false;
		}
	}
	if(!login){
		response.sendRedirect("/WebPress/login.jsp");
	}else{
		if(request.getParameter("action") != null && request.getParameter("action").equals("release")){
			News news = new News();
			news.setTitle(request.getParameter("title"));
			news.setContent(request.getParameter("content"));
			news.setType_name(request.getParameter("type"));
			news.setPic_uris("null");
			news.setAttachement_uris("null");
			NewsDAO.insert(news);
			release = true;
		}
	
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
	var id = 0;
</script>
<script type="text/javascript">
	function changeTitle(itemId)
	{
		document.getElementById("title" + itemId).innerHTML = ("<h2>" + document.getElementById("text" + itemId).value + "</h2>")
		return true;
	}
</script>
<script type="text/javascript">
	function addTitle()
	{
		document.getElementById("main").innerHTML += ("</br><input type=\"text\" id=\"text" + id + "\" onkeyup=\"changeTitle(" + id + ")\" onpaste=\"changeTitle(" + id + ")\" >" + 
													 "</br><h2 id=\"title" + id + "\"></h2>");
		id++;
	}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Release News</title>
</head>
<body>
<%
	if(release){
%>
	<p>Release successfully</p>
<%
	}else{
%>	
	<div id="main">
	</br>
	<button onclick="addTitle()">Add Title</button>
	
	</div>
<%	}
%>

</body>
</html>